package org.valkyrie.gwt.sample.bean.client;

import org.valkyrie.gwt.bean.client.BeanManager;

import com.google.gwt.core.client.EntryPoint;
import com.google.gwt.core.client.GWT;
import com.google.gwt.user.client.ui.HTML;
import com.google.gwt.user.client.ui.RootPanel;

/**
 * 
 * @author Pierre
 * 
 */
public class BeanSampleEntryPoint implements EntryPoint {
	StringBuffer log = new StringBuffer();

	public void onModuleLoad() {

		BeanManager<MyReflectedBean> manager = GWT
				.create(MyReflectedBean.class);

		try {

			manager.setBean(new MyReflectedBean());
			manager.set("name", "Barack Obama");
			String name = manager.get("name");
			appendln(name);

			manager.set("age", 52);
			Integer age = manager.get("age");
			appendln(String.valueOf(age));

			manager.set("value", true);
			boolean value = manager.get("value");
			appendln(String.valueOf(value));

			appendln("MyMyReflectedBean.toString() --> "
					+ manager.getBean().toString());

			appendln("");
			manager.setBean(new MyReflectedBean());

			manager.set("name", "Pierre Bevillard");
			name = manager.get("name");
			appendln(name);

			manager.set("age", 23);
			age = manager.get("age");
			appendln(String.valueOf(age));

			manager.set("value", false);
			value = manager.get("value");
			appendln(String.valueOf(value));

			appendln("MyMyReflectedBean.toString() --> "
					+ manager.getBean().toString());

		} catch (Exception e) {
			appendln(e.getMessage());
		}

		RootPanel.get().add(new HTML(log.toString()));

	}

	private void appendln(String text) {
		log.append(text);
		log.append("<br/>");
	}

}
